package com.kevin.spring.aop.aspectj;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
public class MyInterceptor {

	@Pointcut("execution (* com.kevin.spring.aop.aspectj.PersonServiceImp.*(..))")
	public void myPointCut() {
	}

	@Before("myPointCut()&& args(name)")
	public void before(String name) {
		System.out.println("this is 前置通知" + name);
	}

	@AfterReturning(pointcut = "myPointCut()", returning = "result")
	public void afterReturning(String result) {
		System.out.println("this is 后置通知" + result);
	}

	@After("myPointCut()")
	public void after() {
		System.out.println("this is 最终通知");
	}

	@Around("myPointCut()")
	public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {

		System.out.println("进入方法");
		Object result = pjp.proceed();
		System.out.println("退出方法");

		return result;
	}

	@AfterThrowing("myPointCut()")
	public void afterThrowing() {
		System.out.println("this is @AfterThrowing通知");
	}
}
